/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sv.com.intesal.conexion;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author JM
 */
public class cConexion {

//    private static final String post = "Jdbc:postgresql://localhost:5432/intesal";
//    private static final String usuario = "postgres";
//    private static final String clave = "toor";
    
    //private static final String post = "Jdbc:postgresql://172.17.26.5:1024/intesal";
    private static final String post = "Jdbc:postgresql://localhost:1024/intesal";
    private static final String usuario = "postgres";
    private static final String clave = "rootroot$";

    //private static final String post = "Jdbc:postgresql://192.168.1.9:5432/intesalBD";
    //private static final String usuario = "intesal";
    //private static final String clave = "11-intesalPRD-RI";
    private static Connection con;

    public static Connection conectar() throws SQLException {
        if (con == null || con.isClosed()) {
            con = establecerConexion();
        }
        return con;
    }

    public static Connection conectar(Boolean value) throws SQLException {
        if (con == null || con.isClosed()) {
            con = establecerConexion();
            con.setAutoCommit(value);
        }
        return con;
    }

    private static Connection establecerConexion() {
        Connection cnn = null;
        try {
            DriverManager.registerDriver(new org.postgresql.Driver());
            cnn = DriverManager.getConnection(post, usuario, clave);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return cnn;

        }

    }

    public static Connection conectar_autocommitOFF() throws SQLException {
        if (con == null || con.isClosed()) {
            con = establecerConexion();
            con.setAutoCommit(false);
        }
        return con;
    }

    public static void main(String args[]) {
        try {
            conectar();
        } catch (SQLException ex) {
            Logger.getLogger(cConexion.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
